package com.niannian.dialog;

import com.niannian.dialog.TipDialog.onSimpleOnCancelListener;
import com.niannian.view.HandyTextView;
import com.niannian.R;

import android.content.Context;
import android.view.View;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;

public class SimpleListDialog extends BaseDialog implements
		OnItemClickListener, android.view.View.OnClickListener {

	private HandyTextView title;
	private ListView list;
	private BaseAdapter mAdapter;
	private onSimpleListItemClickListener monSimpleListItemClickListener;
	private TextView cancel;
	private onSimpleOnCancelListener mOnCancelListener;

	public SimpleListDialog(Context context) {
		super(context);
		init();

	}

	private void init() {
		setContentView(R.layout.simplelist);
		cancel = (TextView) findViewById(R.id.btn_cancel);
		title = (HandyTextView) findViewById(R.id.tv_message_title);
		list = (ListView) findViewById(R.id.simple_list);
		list.setOnItemClickListener(this);
		cancel.setOnClickListener(this);
	}

	public void setAdapter(BaseAdapter adapter) {
		mAdapter = adapter;
		if (adapter != null) {
			list.setAdapter(mAdapter);
		}
	}

	public void notifyDataSetChanged() {
		if (mAdapter != null) {
			mAdapter.notifyDataSetChanged();
		}
	}

	public void serOnSimpleListItemClikListener(
			onSimpleListItemClickListener listener) {
		monSimpleListItemClickListener = listener;
	}

	public void setOnCancelListener(onSimpleOnCancelListener listener) {
		mOnCancelListener = listener;
	}

	@Override
	public void onClick(View v) {
		if (v.getId() == R.id.btn_cancel) {
			mOnCancelListener.onCancel();
		}
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		if (monSimpleListItemClickListener != null) {
			monSimpleListItemClickListener.onItemClick(arg2);
		}
	}

	public interface onSimpleListItemClickListener {
		public void onItemClick(int postion);
	}

}
